// <copyright file="CustomViewEngineHelper.cs" company="Clever Software">
// Copyright (c) 2013, 2014 All Right Reserved, http://www.cleversoftware.by
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Clever Software</author>
// <email>info@cleversoftware.by</email>
// <date>2014-02-04</date> 
// <summary>CleverCMS source code</summary>

namespace CleverCMS.Core.Web
{
    using System;
    using System.Collections.Generic;
    using System.Web.Mvc;
    using CleverCMS.Core.Attributes;

    public class CustomViewEngineHelper
    {
        internal static string[] AddNewLocationFormats(IEnumerable<string> defaultLocationFormats, IEnumerable<string> newLocationFormats)
        {
            List<string> allItems = new List<string>(newLocationFormats);

            foreach (string s in defaultLocationFormats)
                allItems.Add(s);

            return allItems.ToArray();
        }
        
        internal static string OverrideMasterPage(string masterName, ControllerContext controllerContext)
        {
            if (NeedChangeMasterPage(controllerContext))
                masterName = Utils.SkinName;
        
            return masterName;
        }

        private static bool NeedChangeMasterPage(ControllerContext context)
        {
            SupportSkinAttribute attr = Attribute.GetCustomAttribute(context.Controller.GetType(), typeof (SupportSkinAttribute)) as SupportSkinAttribute;
            return null != attr;
        }
    }
}